import * as types from './mutation-types'

export const addCrat = function ( { commit, state }, product ) {
    const cartItem = state.items.find( item => item.id === product.id );

    if( !cartItem ) {
        commit( types.PUSH_CART, {  id: product.id, title: product.title, number: 1, } )
    }else {
        commit( types.ADD_ITEM, cartItem )
    }
}
